layui.use(['table', 'admin', 'ax', 'laydate'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var laydate = layui.laydate;

    /**
     * 库位表管理
     */
    var BasicPosition = {
        tableId: "basicPositionTable"
    };

    /**
     * 初始化表格的列
     */
    BasicPosition.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'id', hide: true, title: '主键'},
            {field: 'positionAreaName', sort: true, title: '所属库区',width: 120},
            {field: 'positionNumber', sort: true, title: '库位编号',width: 140},
            {field: 'positionType', sort: true, title: '库位类型'},
            {field: 'positionFunction', sort: true, title: '库区功能'},
            {field: 'positionCondition', sort: true, title: '保管条件'},
            {field: 'positionAreaType', sort: true, title: '库区类型'},
            {field: 'positionProducttype', sort: true, title: '品类'},
            {field: 'positionPutorder', hide: true, title: '入库顺序'},
            {field: 'positionPickingorder', hide: true, title: '拣货顺序'},
            {field: 'positionAvailable', hide: true, title: '可用容量'},
            {field: 'positionAlready', hide: true, title: '已用容量'},
            {field: 'positionState', sort: true, title: '库位状态'},
            {align: 'center', toolbar: '#tableBar', title: '操作',fixed: 'right'}
        ]];
    };

    /**
     * 点击查询按钮
     */
    BasicPosition.search = function () {
        var queryData = {};
        queryData['condition'] = $("#condition").val();
        table.reload(BasicPosition.tableId, {
            where: queryData, page: {curr: 1},
             done:function () {
                 // 搜索按钮点击事件
                 $('#btnSearch').click(function () {
                	 BasicPosition.search();
                 });
            }
        });
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + BasicPosition.tableId,
        url: Feng.ctxPath + '/storagePutSingle/positionList?storageNumber='+$("#storageNumber").val(),
        page: true,
        limit: 10,
        height: "full-60",
        toolbar: '#toolbarfrom',
        cellMinWidth: 100,
        cols: BasicPosition.initColumn()
    });


    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
    	BasicPosition.search();
    });
    
    //回填库位数据
    function confirm(data){
    	parent.StoragePutSingleInfoDlg.data.positionNumber = data.positionNumber;//库位编号
    	var Index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Index);
    }
    
    // 双击行事件
    table.on('rowDouble(' + BasicPosition.tableId + ')', function (obj) {
        var data = obj.data;
    	confirm(data);
    });

    // 工具条点击事件
    table.on('tool(' + BasicPosition.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        if (layEvent === 'confirm') {
        	confirm(data);
        } 
    });
});
